{template header}

<div class="container">

<div class="row">

<div class="col-md-8">

    {template menu}


    <div class="bbox bbox-nbt" id="info" >

    <ul class="nav nav-pills" style="padding: 10px;">
        {if isMobile()}
        <li>
            <select onchange="jumpto(this.options[this.options.selectedIndex].value)" name="typeid" id="typeid" class="form-control">
                <option value="{tsUrl('user','duty',array('id'=>$strUser['userid']))}" selected >服务</option>
                <option value="{tsUrl('user','event',array('id'=>$strUser['userid']))}" >活动</option>
                <option value="{tsUrl('user','article',array('id'=>$strUser['userid']))}" >文档</option>
                <option value="{tsUrl('user','wish',array('id'=>$strUser['userid']))}" >心愿</option>
                <option value="{tsUrl('user','gift',array('id'=>$strUser['userid']))}" >义卖</option>
                <option value="{tsUrl('user','weibo',array('id'=>$strUser['userid']))}">动态</option>
                {if $GLOBALS['TS_USER']['isadmin']=='1'}
                <option value="{tsUrl('user','comment',array('id'=>$strUser['userid']))}" >备注</option>
                {/if}

            </select>
        </li>
        {else}
        <li role="presentation" class="active"><a href="{tsUrl('user','duty',array('id'=>$strUser['userid']))}">服务</a></li>
        <li role="presentation"><a href="{tsUrl('user','event',array('id'=>$strUser['userid']))}">活动</a></li>
        <li role="presentation"><a href="{tsUrl('user','article',array('id'=>$strUser['userid']))}">文档</a></li>
        <li role="presentation"><a href="{tsUrl('user','wish',array('id'=>$strUser['userid']))}">心愿</a></li>
        <li role="presentation"><a href="{tsUrl('user','gift',array('id'=>$strUser['userid']))}">义卖</a></li>
        <li role="presentation"><a href="{tsUrl('user','weibo',array('id'=>$strUser['userid']))}">动态</a></li>
        {if $GLOBALS['TS_USER']['isadmin']=='1'}
        <li role="presentation"><a href="{tsUrl('user','comment',array('id'=>$strUser['userid']))}" style="color: green">备注</a></li>
        {/if}
        {/if}
    </ul>

<div class="bc">


<div class="topic_list" id="duty_list">

<ul>
    {if $arrDuty}
{loop $arrDuty $key $item}
    <li>
        <div class="userimg">
            <img class="img-rounded" src="{$strUser[face]}" width="32" height="32" alt="{$item['user']['username']}" title="{$item['user']['username']}" />
        </div>

        <div class="topic_title">
            <div class="title">
            <div class="author">{$strUser['username']}<span style="float: right;color: #c0c0c0">{$item[count_recommend]} 赞</span></div>

            <div  class="content" style="color:{if $item['status']==0}#c0c0c0{else}#000000{/if}"   onclick="redirect({$item['dutyid']})">
    {if $item['endtime']==0}{php echo date('Y-m-d',$item['begintime'])}{else}{php echo date('Y-m-d H:i',$item['begintime'])}至{php echo date('H:i',$item['endtime'])}{/if}在<a href="{tsUrl('duty','index',array('groupid'=>$item['groupid']))}">{php echo $item['address']}</a>执行{$item['cate']}，{if $item['commute']==0}服务{php echo $item['period']}小时{else}实际服务{$item['period']}小时，通勤时间{php echo $item['commute']}小时，合计耗时{php echo $item['term']}小时{/if}。<br/>{if $item['job']}<br/>{php echo delempty($item['job'])}{/if}&nbsp;&nbsp;
            </div>
    {if $item['image']}

    <div class="piclist">
        <ul>
            {loop $item['image'] $k $pic}
            <li style="border-bottom: none"><a href="{$pic}"><img style="width:100px;height: auto;position:absolute; clip:rect(0px 120px 70px 0px); " src="{$pic}"></a></li>

            {/loop}
        </ul>
    </div>
    {/if}
    {if $item['comment']}

    <ul style="background-color: #f7f7f7;border-radius: 5%;margin-top: 20px">
        {loop $item['comment'] $k $v}
        <li style="border-bottom: 0px;">
            <div class="userimg"><a href="{tsUrl('user','duty',array('id'=>$v[user][userid]))}"><img class="img-rounded" src="{$v[user][face]}" width="32" height="32" alt="{$v['user']['username']}" title="{$v['user']['username']}" /></a></div>
            <div class="topic_title">
                <div class="title">
                    <div class="author"><a href="{tsUrl('user','duty',array('id'=>$v[user][userid]))}">{$v[user][username]}</a>&nbsp;&nbsp;{php echo getTime($v[addtime],time())}</div>

                    <div class="content">{$v[content]}</div>
                </div>
            </div>

        </li>

        {/loop}
    </ul>

    {/if}

    <div class="tar">
        {if $GLOBALS[TS_USER][userid]==$item['userid']&&$item['status']==1}

        <a class="btn btn-w" style="background-color: #419641;color: #FFFFFF" href="{tsUrl('duty','card',array('dutyid'=>$item[dutyid]))}">打卡</a>

        {/if}

        {if $item['articleid']>0}
        <a class="btn btn-w" href="{tsUrl('article','show',array('id'=>$item[articleid]))}">读文档</a>
        {/if}

    {if $GLOBALS[TS_USER][userid]==$item['userid']}

        <a class="btn btn-w"  href="javascript:void('0');" onclick="doBindForm('{php echo($key*1+1)}')">绑定文档</a>

    {/if}
        {if $item['status']==0&&($GLOBALS['TS_USER']['isadmin']=='1'||$GLOBALS[TS_USER][userid]==$item['userid'])}<a  class="btn btn-w" href="{tsUrl('duty','show',array('dutyid'=>$item[dutyid],'edit'=>1))}" >修改</a>{/if}
        {if $item['status']==0&&($GLOBALS['TS_USER']['isadmin']=='1'||$GLOBALS[TS_USER][userid]==$item['userid'])}<a  class="btn btn-w" href="javascript:void('0');" onclick="delDuty('{$item['dutyid']}')">删除</a>{/if}

    {if (in_array($GLOBALS[TS_USER][userid],$item['group']['admin'])||$GLOBALS['TS_USER']['isadmin']=='1')&&$item['status']==0}<a class="btn btn-w" href="javascript:void('0');" onclick="verify('{$item['dutyid']}')">核定</a>{/if}
    {if (in_array($GLOBALS[TS_USER][userid],$item['group']['admin'])||$GLOBALS['TS_USER']['isadmin']=='1')&&$item['status']==1}<a class="btn btn-w" href="javascript:void('0');" onclick="cancel('{$item['dutyid']}')">取消核定</a>{/if}
    {if $GLOBALS[TS_USER][userid]&&$item['status']==1&&$item[userid]!=$GLOBALS[TS_USER][userid]}
    <a class="btn btn-w" href="javascript:void('0');" onclick="recommend({$item['dutyid']})">{if $isRecommend==0} 点赞{else} 取消点赞{/if}</a>
    {/if}
    {if $GLOBALS[TS_USER][userid]>0}
    <a class="btn btn-w" href="javascript:void(0)" onclick="add_comment('{$item[dutyid]}')">评论</a>
    {/if}

    </div>
</div>
</div>
</li>
{/loop}
    {else}
    <li>没有服务记录</li>
    {/if}
</ul>

</div>

<div id="do_duty_form" style="display: none">
    <br/>
    <form  id="record" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=user&ac=do&ts=add">
        <input type="hidden" id='idcard' name="idcard" value="{$strUser['idcard']}">
        <input type="hidden" id='username' name="username" value="{$strUser['username']}">
        <input type="hidden" id='userid' name="userid" value="{$strUser['userid']}">
        <div class="form-group">
            <label class="col-sm-3 control-label">服务类型</label>
            <div class="col-sm-9">
                <select  name="cateid" id="cateid" class="form-control">
                    <option value=""></option>
                    {loop $strCate $key $item}
                    <option value="{$item['cateid']}" >{$item['catename']}</option>
                    {/loop}
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">服务处所</label>
            <div class="col-sm-9">
                <select  name="groupid" id="gid" class="form-control">
                    <option value=""></option>
                    {loop $arrGroup $key $item}
                    <option value="{$item['groupid']}" >{$item['groupname']}</option>
                    {/loop}
                </select>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">服务起始时间</label>
            <div class="col-sm-3">
                <input class="form-control" name="begindate" readonly value="" id="beginDate" />
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">服务结束时间</label>
            <div class="col-sm-3">
                <input class="form-control" name="enddate" readonly value="" id="endDate" />
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">实际耗时（小时）</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" name="period" id="period" placeholder="可留空，根据起止时间自动计算">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">通勤时长（小时）</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" name="commute" id="commute" value="{$lastDuty[commute]}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">工作小结及注意事项</label>
            <div class="col-sm-9" >
                <div id="tseditor"></div>
                <div style="display: none">
                    <textarea name="content" class="form-control" style="width: 100%"  rows="5" placeholder="简要记录一下做了什么，以及需要提醒伙伴注意的情况"></textarea>
                </div>
                <!--<div  name="job" id="tseditor" rows="5" placeholder="简要记录一下做了什么，以及需要提醒伙伴注意的情况">-->
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button data-id="submit" type="submit" class="btn btn-success">点击提交</button>
            </div>
        </div>
    </form>

</div>


<div class="clear"></div>
<div class="page">{$pageUrl}</div>
</div>
</div>
</div>


</div>
</div>
{loop $arrDuty $key $duty}
<div id="do_bind_form{php echo($key*1+1)}" style="display:none;">

    <form  id="comm-form" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=user&ac=do&ts=bind">
        <div class="form-group">
            <label>&nbsp;&nbsp;&nbsp;请选择一篇文档</label>
        </div>
        <div class="form-group">

            <div class="col-sm-10">
                <select  name="articleid" id="articleid" class="form-control">
                    {loop $arrArticle $key $item}
                    <option value="{$item['articleid']}{$mylink}">{$item['title']}</option>
                    {/loop}
                </select>
            </div>

            </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="hidden" id="dutyid" name="dutyid" value="{$duty[dutyid]}">
                <button type="submit" class="btn btn-success">点击提交</button>
            </div>
        </div>
    </form>

</div>


{/loop}

<div id="do_date_form1" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title">选择范围</h5>
            </div>
            <div class="modal-body" >
                <form  id="date-form" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=duty&ac=exporttext">
                    <input type="hidden" id='userid' name="userid" value="{$strUser['userid']}">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">起始日期</label>
                        <div class="col-sm-3"><select   id="begin_year" name='beginyear' class="form-control"></select></div>
                        <div class="col-sm-3"><select   id="begin_month" name='beginmonth' class="form-control"></select></div>
                        <div class="col-sm-3"><select   id="begin_day" name="beginday" class="form-control"></select></div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">截止日期</label>
                        <div class="col-sm-3"><select  id="end_year" name="endyear" class="form-control"></select></div>
                        <div class="col-sm-3"><select  id="end_month" name="endmonth" class="form-control"></select></div>
                        <div class="col-sm-3"><select  id="end_day" name="endday" class="form-control"></select></div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-success">点击提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>

    //隐藏列表，显示登记表单
    function showdutyform(){
        $('#duty_list').hide();
        $('#do_duty_form').show();
    }

    //绑定文档
    function doBindForm(key){

        if(key==0){
            tsNotice('非法操作！');
        }else{
            var content = $("#do_bind_form"+key).html();
            tsNotice(content);
        }
    }
    //删除服务记录
    function delDuty(dutyid){


        if (confirm('删除这条服务记录吗？')) {

            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=user&ac=do&ts=del",
                data: "dutyid="+dutyid,
                beforeSend:function(){
                },
                success:function(result){
                    if(result == '1'){
                        window.location.reload();
                    }
                }
            });

        }
    }
    //确认服务记录
    function verify(dutyid){


        if (confirm('确认这条服务记录吗？')) {

            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=user&ac=do&ts=verify",
                data: "dutyid="+dutyid,
                beforeSend:function(){
                },
                success:function(result){
                        window.location.reload();
                }
            });

        }
    }

    //取消确认
    function cancel(dutyid){

        if (confirm('取消确认这条服务记录吗？')) {

            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=user&ac=do&ts=cancel",
                data: "dutyid="+dutyid,
                beforeSend:function(){
                },
                success:function(result){
                        window.location.reload();
                }
            });
        }
    }

    $(function(){


        $('#record').on('submit', function(e) {
            var userid =$('#userid').val();
            var idcard = $.trim($('#idcard').val());
            var username = $('#username').val();
            var groupid  = $('#gid').val();
            var cateid  = $('#cateid').val();
            var begindate  = $('#begindate').val();
            var enddate  = $('#enddate').val();
            var period  = $('#period').val();
            var commute  = $('#commute').val();
            var job  = $('content').val();

            if (cateid == '') {
                bootbox.alert('服务类型不能为空');
                return false;
            }

            if (groupid == '') {
                bootbox.alert('服务处所不能为空');
                return false;
            }
            if (cateid == '1' && groupid=='1') {
                bootbox.alert('服务类型与服务处所不匹配');
                return false;
            }

            if (begindate == '') {
                bootbox.alert('起始时间不能为空');
                return false;
            }
            if (enddate == '') {
                bootbox.alert('结束时间不能为空');
                return false;
            }



             $.ajax({
             url: "{SITE_URL}index.php?app=user&ac=do&ts=add",
             type: 'POST',
             dataType: 'json',
             data: {userid:userid,idcard:idcard,groupid:groupid,cateid:cateid,year:year,month:month,day:day,beginhour:beginhour,beginmin:beginmin,endhour:endhour,endmin:endmin,period:period,commute:commute,username:username,job:job},
             beforeSend:function(){
             },
             success:function(result){
                     window.location.reload();
             }
             });

        });




    });

    $('#beginDate').datetimepicker({
        language:  'zh-CN',
        format: 'yyyy-mm-dd hh:ii',
        autoclose: true,
        minView:0
    });

    $('#endDate').datetimepicker({
        language:  'zh-CN',
        format: 'yyyy-mm-dd hh:ii',
        autoclose: true,
        minView:0
    });
</script>

{template footer}